package dialogs;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.newxlmedical.R;

import beans.NewUserInfoBean;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import constants.Constants;
import constants.HandlerConstant;
import custom.MyDialog;
import customhandler.MyHandler;
import singleton.SingletonClass;
import utils.FormateUtils;
import utils.ObjectSaveUtil;

/**
 * Created by Administrator on 2018/4/19.
 */

public class SignOutDialog extends MyDialog {

    @BindView(R.id.text_user_name)
    TextView textUserName;
    @BindView(R.id.text_user_role)
    TextView textUserRole;
    @BindView(R.id.iv_sign_out_icon)
    ImageView ivIcon;

    private Context mContext;
    //    private ACache mCache;
    private OnClickListener mOnClickListener = null;
    private MyHandler allHnadler = SingletonClass.getSingleton(MyHandler.class);
    public SignOutDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        this.mContext = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_sign_out);
        ButterKnife.bind(this);
        Log.e("BaseActivity", "SignOutDialog: " );
//        mCache = ACache.get(mContext);
//        if (mCache.getAsString("USERNAME") != null) {
//            textUserName.setText(mCache.getAsString("USERNAME").toString());
//        }
        NewUserInfoBean.DataBean dataBean = (NewUserInfoBean.DataBean) ObjectSaveUtil.readObject(mContext, Constants.USER_INFO_BEAN, Constants.USER_INFO_BEAN);
        if (dataBean != null) {
            textUserName.setText(dataBean.getName());
            textUserRole.setText(FormateUtils.getRole(dataBean.getRoleInfoId()));
        }

        if (dataBean != null) {
            if (dataBean.getRoleInfoId() == Constants.ROLE_NURSE) { //护士
                ivIcon.setImageResource(R.mipmap.role_nurse);
            } else if (dataBean.getRoleInfoId() == Constants.ROLE_HEAD_NURSE) { //护士长
                ivIcon.setImageResource(R.mipmap.role_head_nurse);
            } else if (dataBean.getRoleInfoId() == Constants.ROLE_MANAGE) { //高层管理
                ivIcon.setImageResource(R.mipmap.role_manage);
            } else if (dataBean.getRoleInfoId() == Constants.ROLE_FACTORY) { //供应商
                ivIcon.setImageResource(R.mipmap.role_supplier);
            } else { //厂商
                ivIcon.setImageResource(R.mipmap.role_supplier);
            }
        }
    }

    @OnClick({R.id.btn_close, R.id.btn_sign_out})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_close:
                cancel();
                break;
            case R.id.btn_sign_out:
                mOnClickListener.onClick(view, this);
                break;
        }
    }

    public interface OnClickListener {
        void onClick(View v, Dialog dialog);
    }

    public void setOnClickListener(OnClickListener mOnClickListener) {
        this.mOnClickListener = mOnClickListener;
    }
}
